class MinigameFlyingVolume extends PhysicsVolume;

enum CameraLocations {
     CL_Behind,
     CL_Front,
     CL_Left,
     CL_Right,
     CL_Cinema
};

var() vector          PlayerVelocity;
var() rotator         PlayerRotation;
var() CameraLocations CameraLocation;
var() float           CameraDistance;
var() float           AccelerationFactor;
var() float           DecelerationFactor;
var() float           PlayerPropelFactor;

var() bool            WallHitKill;
var() bool            Invincibility;

simulated function PostBeginPlay ()
{

    super.PostBeginPlay();
    PlayerRotation *= 182.0444444;

}

simulated event PawnEnteredVolume(Pawn Other)
{

    local EnyaraPlayerController mgPC;
    mgPC = EnyaraPlayerController(level.GetLocalPlayerController());

    mgPC.PlayerPropelFactor = PlayerPropelFactor;
    mgPC.Pawn.AirSpeed = PlayerPropelFactor;
    mgPC.DesiredPlayerLocation = vect(0,0,0);
    mgPC.UseDesiredPlayerLocation = vect(0,0,0);
    mgPC.DesiredCameraDistance = CameraDistance;
    mgPC.CameraTimeInVolume = 0;

    switch (CameraLocation) {

        case CL_Left:
            mgPC.DesiredCameraRotation = rot(0, 16384, 0);
            if (PlayerRotation.Yaw % 32768 == 0) {
                if (PlayerRotation.Pitch % 16384 == 0) {
                    mgPC.DesiredPlayerLocation.Y = Location.Y;
                    mgPC.UseDesiredPlayerLocation.Y = 1;
                }
            } else if (PlayerRotation.Yaw % 16384 == 0) {
                if (PlayerRotation.Pitch % 16384 == 0) {
                    mgPC.DesiredPlayerLocation.X = Location.X;
                    mgPC.UseDesiredPlayerLocation.X = 1;
                }
            }
            break;

        case CL_Right:
            mgPC.DesiredCameraRotation = rot(0, -16384, 0);
            if (PlayerRotation.Yaw % 32768 == 0) {
                if (PlayerRotation.Pitch % 16384 == 0) {
                    mgPC.DesiredPlayerLocation.Y = Location.Y;
                    mgPC.UseDesiredPlayerLocation.Y = 1;
                }
            } else if (PlayerRotation.Yaw % 16384 == 0) {
                if (PlayerRotation.Pitch % 16384 == 0) {
                    mgPC.DesiredPlayerLocation.X = Location.X;
                    mgPC.UseDesiredPlayerLocation.X = 1;
                }
            }
            break;

        case CL_Front:
            mgPC.DesiredCameraRotation = rot(0, 32768, 0);
            break;

        case CL_Behind: default:
            mgPC.DesiredCameraRotation = rot(0, 0, 0);
            break;

    }

    // Set the desired rotations for both the pawn and the camera
    // Make sure the camera starts slowing down when it's 70% done

    mgPC.DesiredPlayerRotation = PlayerRotation;
    mgPC.DesiredCameraRotation += mgPC.DesiredPlayerRotation;
    mgPC.CameraRotationSlowdownDistance = mgPC.RSize(mgPC.DesiredCameraRotation - mgPC.ActualCameraRotation) * 0.3;

    // There's going to be a static acceleration towards the camera's final position

    mgPC.CameraRotationAcceleration = mgPC.DesiredCameraRotation - mgPC.ActualCameraRotation;

    mgPC.CurrentFlyingVolume = self;
    mgPC.LastRotationHasEnded = false;

    mgPC.ClientMessage(mgPC.DesiredCameraRotation.Pitch@mgPC.DesiredCameraRotation.Yaw@mgPC.DesiredCameraRotation.Roll);

}

simulated event PawnLeavingVolume(Pawn Other)
{
    local EnyaraPlayerController mgPC;
    mgPC = EnyaraPlayerController(level.GetLocalPlayerController());

    if (mgPC.Pawn.PhysicsVolume.Class!=class'MinigameFlyingVolume') {
        mgPC.PlayerKill();
    }
	//super.PawnLeavingVolume(Other);
	//level.GetLocalPlayerController().ClientMessage("Now leaving"@Self);
	//bBlockActors = True;
}

defaultproperties
{
     PlayerVelocity=(X=1,Y=0,Z=0)           // 1 is the default speed
     PlayerRotation=(Pitch=0,Yaw=0,Roll=0)  // The default rotation is headed straight down the X-Axis
     CameraLocation=CL_Behind               // The default view is behind the player
     CameraDistance=1                       // 1 is the default camera distance
     AccelerationFactor=1                   // 1 is the default acceleration factor; the higher it is, the faster they accelerate
     DecelerationFactor=0.98                // The closer to 0, the slower they decelerate
     PlayerPropelFactor=512
     WallHitKill=true
     Invincibility=false

     LocationName="flying animal"
}
